from django.shortcuts import render
from .models import *
from .filters import *
from .serializers import *
from apps.base.serializers import *
from utils.pagination import LargeResultsSetPagination
from rest_framework import viewsets
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend


class CustomerViewSet(viewsets.ModelViewSet):
    serializer_class = CustomerSerializer

    queryset = Customer.objects.all().order_by('-A001')
    filter_backends = (DjangoFilterBackend,filters.SearchFilter,filters.OrderingFilter)
    filter_class = CustomerFilter
    search_fields = ['A001','B001','B008']
    ordering_fields = ('A001','B001','B008')
    pagination_class = LargeResultsSetPagination


class ContactsViewSet(viewsets.ModelViewSet):
    serializer_class = ContactsSerializer
    filter_backends = (filters.SearchFilter,)
    search_fields = ['F001__B001']
    queryset = Contacts.objects.all()
    pagination_class = LargeResultsSetPagination


class QuotationViewSet(viewsets.ModelViewSet):
    serializer_class = ContactsSerializer
    filter_backends = (filters.SearchFilter,)
    search_fields = ['F001__B001']
    queryset = Quotation.objects.all()
    pagination_class = LargeResultsSetPagination
